package cn.com.aiouyi.entity;

import java.io.Serializable;

import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Min;

import org.apache.commons.lang3.builder.CompareToBuilder;

import lombok.Getter;
import lombok.Setter;

/**
 * Entity - 排序基类
 * @author hanson
 */
@MappedSuperclass
@Getter
@Setter
public abstract class SeqEntity<ID extends Serializable> extends BaseEntity<ID> implements Comparable<SeqEntity<ID>> {

	private static final long serialVersionUID = 2985598734943661667L;

	/** "排序"属性名称 */
	public static final String SORT_PROPERTY_NAME = "seq";

	/** 排序 */
	@Min(0)
	private Integer seq = 0;


	/**
	 * 实现compareTo方法
	 * @param seqEntity 排序对象
	 * @return 比较结果
	 */
	public int compareTo(SeqEntity<ID> seqEntity) {
		if (seqEntity == null) {
			return 1;
		}
		return new CompareToBuilder().append(getSeq(), seqEntity.getSeq()).append(getId(), seqEntity.getId()).toComparison();
	}

}
